asm
  ld sp,$CFFF
  end asm

#include "./library/smsrnd.bas"

dim i as uinteger at $C010
dim eee as uinteger at $C012
dim seed as uinteger at $C014
dim delaytime as uinteger at $C016
dim ee2 as uinteger at $C018
dim ee3 as uinteger at $C01A
dim ee4 as uinteger at $C01C
dim ee5 as uinteger at $C01E
dim ex0 as uinteger at $C020
dim ey0 as uinteger at $C022
dim ej0 as uinteger at $C024
dim ej1 as uinteger at $C026

sub tsamuraiputchar(txpos as uinteger,typos as uinteger,tchar as ubyte,tattr as ubyte, tlayer as ubyte):
  poke ($E000*(1-(tlayer band 1)))+((txpos bxor 31)*32)+typos,tchar
  poke ($E401*(1-(tlayer band 1)))+(typos*2),tattr
  poke ($E800*(tlayer band 1))+((txpos bxor 31)*64)+(typos*2),tchar
  poke ($E801*(tlayer band 1))+((txpos bxor 31)*64)+(typos*2),tattr
  end sub

sub tsamuraiscroll(tid as uinteger,tvl as ubyte):
  poke $E400+(tid*2),tvl
  end sub

sub tsamuraiputsprite(tlayer as uinteger, txpos as ubyte, typos as ubyte, tid as ubyte, tattr as ubyte):
  poke $F000+(tlayer*4),txpos
  poke $F001+(tlayer*4),tid
  poke $F002+(tlayer*4),tattr
  poke $F003+(tlayer*4),typos
  end sub

seed=0
delaytime=100

for ee2=0 to 31
  for ee3=0 to 31
    tsamuraiputchar(ee3,ee2,code("."),1,0)
    tsamuraiputchar(ee3,ee2,code("-"),2,1)
    next:next

for ee2=0 to 15
  for ee3=0 to 15
    tsamuraiputchar(ee3+12,ee2+14,ee3+(ee2*16),3,0)
    next:next

ex0=40:ey0=40
eee=0
do
  ej0=peek($F800)
  ej1=peek($F801)
  tsamuraiputchar(8,28,48+(ej0 mod 10),0,0)
  tsamuraiputchar(7,28,48+((int(ej0/10)) mod 10),0,0)
  tsamuraiputchar(6,28,48+((int(ej0/100)) mod 10),0,0)
  tsamuraiputchar(8,29,48+(ej1 mod 10),0,0)
  tsamuraiputchar(7,29,48+((int(ej1/10)) mod 10),0,0)
  tsamuraiputchar(6,29,48+((int(ej1/100)) mod 10),0,0)
  for ee2=0 to 31
    tsamuraiscroll(ee2, peek( @scroll01+((ee2+eee)band 7) ) )
    next
  for ee2=0 to 5
    for ee3=0 to 5
      tsamuraiputsprite(ee3+(ee2*6),ex0+(ee3*32),ey0+(ee2*32),eee band $07,eee band $1F)
      next:next
  ex0=ex0+((ej0 band 1)/1)-((ej0 band 2)/2)
  ey0=ey0+((ej0 band 8)/8)-((ej0 band 4)/4)
  for ee5=1 to 100:next
  eee=eee+1
  loop

scroll01:
asm
  defb 4,3,2,1,0,1,2,3
  end asm

'-------------------------------------------------------------------------------

  '- not for deleting - scroll
  'for ee2=0 to 31
  '  seed=smsrnd(seed)
  '  tsamuraiscroll(ee2,seed)
  '  for i=1 to delaytime:next
  '  next


  eee=0
  do
    for ee2=0 to 5
      for ee3=0 to 5
        tsamuraiputsprite(ee3+(ee2*6),eee+(ee3*32),eee+(ee2*32),eee band $07,eee band $1F)
        next:next
    eee=eee+1
    for ee5=1 to 1000:next
    loop


do
  for ee2=$000 to $3FF
    tsamuraiputchar(9,25,code("-"),0,0)
    tsamuraiputchar(8,25,48+(ee2 mod 10),0,0)
    tsamuraiputchar(7,25,48+((int(ee2/10)) mod 10),0,0)
    tsamuraiputchar(6,25,48+((int(ee2/100)) mod 10),0,0)
    tsamuraiputchar(5,25,48+((int(ee2/1000)) mod 10),0,0)
    tsamuraiputchar(4,25,code("-"),0,0)
    ee5=peek($F000+ee2)
    for ee3=0 to 255
      tsamuraiputchar(9,26,code("-"),0,0)
      tsamuraiputchar(8,26,48+(ee3 mod 10),0,0)
      tsamuraiputchar(7,26,48+((int(ee3/10)) mod 10),0,0)
      tsamuraiputchar(6,26,48+((int(ee3/100)) mod 10),0,0)
      tsamuraiputchar(5,26,48+((int(ee3/1000)) mod 10),0,0)
      tsamuraiputchar(4,26,code("-"),0,0)
      for ee4=1 to delaytime/5:next
      poke $F000+ee2,ee3
      next
    poke $F000+ee2,ee5
    next
  loop

'-------------------------------------------------------------------------------

  'for eee=$000 to $3FF '- sprites
  '  seed=smsrnd(seed)
  '  poke $F000+eee,seed
  '  next

  'for eee=$000 to $3FF step 4 '- sprites
  '  seed=smsrnd(seed)
  '  poke $F001+eee,(seed band 15)
  '  next


eee=0
do
  for ee2=$000 to $3FF
    seed=smsrnd(seed)
    poke $F000+ee2,seed
    'poke $F000+ee2,eee+ee2
    for ee3=1 to 100:next
    next
  eee=eee+1
  loop

  'for eee=$100 to $1FF '- sprites
  '  seed=smsrnd(seed)
  '  poke $F000+eee,seed
  '  for i=1 to delaytime:next
  '  next

  'for eee=$200 to $2FF '- sprites
  '  seed=smsrnd(seed)
  '  poke $F000+eee,seed
  '  for i=1 to delaytime:next
  '  next

  'for eee=$300 to $3FF '- sprites
  '  seed=smsrnd(seed)
  '  poke $F000+eee,seed
  '  for i=1 to delaytime:next
  '  next






do

  for eee=0 to $3FF '- sprites
    'for i=1 to delaytime:next
    poke $F000+eee,seed:seed=smsrnd(seed)
    next

  for eee=0 to $3FF '- fg-videoram
    for i=1 to delaytime:next
    poke $E000+eee,seed:seed=smsrnd(seed)
    next

  for eee=0 to $3F step 2 '- fg-colorram (?) scroll?
    for i=1 to delaytime:next
    poke $E400+eee,seed:seed=smsrnd(seed)
    next

  for eee=0 to $3F step 2 '- fg-colorram (?) attr?
    for i=1 to delaytime:next
    poke $E401+eee,seed:seed=smsrnd(seed)
    next

  'for eee=0 to $3DF '- fg-colorram (?)
  '  for i=1 to delaytime:next
  '  poke $E420+eee,seed:seed=smsrnd(seed)
  '  next

  for eee=0 to $7FF step 2 '- bg
    for i=1 to delaytime:next
    poke $E800+eee,seed:seed=smsrnd(seed)
    next

  for eee=0 to $7FF step 2 '- bg
    for i=1 to delaytime:next
    poke $E801+eee,seed:seed=smsrnd(seed)
    next


  loop

do:loop

  for eee=$E000 to $F3FF
    for i=1 to 100:next
    seed=smsrnd(seed)
    poke eee,seed
    next

'-------------------------------------------------------------------------------

'- AM_RANGE(0xe000, 0xe3ff) AM_RAM_WRITE(tsamurai_fg_videoram_w) AM_SHARE("videoram")
'- AM_RANGE(0xe400, 0xe43f) AM_RAM_WRITE(tsamurai_fg_colorram_w) AM_SHARE("colorram")
'- AM_RANGE(0xe800, 0xefff) AM_RAM_WRITE(tsamurai_bg_videoram_w) AM_SHARE("bg_videoram")
'- AM_RANGE(0xf000, 0xf3ff) AM_RAM AM_SHARE("spriteram")




'- AM_RANGE(0x0000, 0xbfff) AM_ROM
'- AM_RANGE(0xc000, 0xcfff) AM_RAM

'- /* protection? - there are writes as well...*/
'- AM_RANGE(0xd803, 0xd803) AM_READ(unknown_d803_r)
'- AM_RANGE(0xd806, 0xd806) AM_READ(unknown_d806_r)
'- AM_RANGE(0xd900, 0xd900) AM_READ(unknown_d900_r)
'- AM_RANGE(0xd938, 0xd938) AM_READ(unknown_d938_r)

'- AM_RANGE(0xe000, 0xe3ff) AM_RAM_WRITE(tsamurai_fg_videoram_w) AM_SHARE("videoram")
'- AM_RANGE(0xe400, 0xe43f) AM_RAM_WRITE(tsamurai_fg_colorram_w) AM_SHARE("colorram")
'- AM_RANGE(0xe440, 0xe7ff) AM_RAM
'- AM_RANGE(0xe800, 0xefff) AM_RAM_WRITE(tsamurai_bg_videoram_w) AM_SHARE("bg_videoram")
'- AM_RANGE(0xf000, 0xf3ff) AM_RAM AM_SHARE("spriteram")

'- AM_RANGE(0xf400, 0xf400) AM_WRITENOP
'- AM_RANGE(0xf401, 0xf401) AM_WRITE(sound_command1_w)
'- AM_RANGE(0xf402, 0xf402) AM_WRITE(sound_command2_w)

'- AM_RANGE(0xf800, 0xf800) AM_READ_PORT("P1")
'- AM_RANGE(0xf801, 0xf801) AM_READ_PORT("P2") AM_WRITE(tsamurai_bgcolor_w)
'- AM_RANGE(0xf802, 0xf802) AM_READ_PORT("SYSTEM") AM_WRITE(tsamurai_scrolly_w)
'- AM_RANGE(0xf803, 0xf803) AM_WRITE(tsamurai_scrollx_w)
'- AM_RANGE(0xf804, 0xf804) AM_READ_PORT("DSW1")
'- AM_RANGE(0xf805, 0xf805) AM_READ_PORT("DSW2")

'- AM_RANGE(0xfc00, 0xfc00) AM_WRITE(flip_screen_w)
'- AM_RANGE(0xfc01, 0xfc01) AM_WRITE(nmi_enable_w)
'- AM_RANGE(0xfc02, 0xfc02) AM_WRITE(tsamurai_textbank1_w)
'- AM_RANGE(0xfc03, 0xfc04) AM_WRITE(tsamurai_coin_counter_w)

'---------------------------------------------------------------------------------
'dim ee2 as uinteger at $4C06
'dim ee3 as uinteger at $4C08
'dim ee4 as ubyte at $4C0A
'dim ecsp as ubyte at $4C0C
'dim ecsq as ubyte at $4C0E
'


'dim ex1 as uinteger at $4C14
'dim ey1 as uinteger at $4C16
'dim ex2 as uinteger at $4C18
'dim ey2 as uinteger at $4C1A
'dim ex3 as uinteger at $4C1C
'dim ey3 as uinteger at $4C1E
'
'dim ex4 as uinteger at $4C20
'dim ey4 as uinteger at $4C22
'dim ex5 as uinteger at $4C24
'dim ey5 as uinteger at $4C26
'dim ex6 as uinteger at $4C28
'dim ey6 as uinteger at $4C2A
'dim ex7 as uinteger at $4C2C
'dim ey7 as uinteger at $4C2E
'
'
'function test1(t1 as uinteger,t2 as uinteger,t3 as uinteger,t4 as uinteger)  as uinteger
'  end function
'
'sub zpoke(t1 as uinteger,t2 as ubyte)
'  poke t1,t2
'  end sub
'
'sub putchar(tx1 as uinteger, ty1 as uinteger, tch1 as uinteger)
'  poke ($4000+(tx1*32)+ty1) bxor %0000001111100000,(tch1 band 255)
'  end sub
'
'pacmanputsprite(0,21,10,4,3)
'pacmanputsprite(1,21,30,4,3)
'pacmanputsprite(2,21,50,4,3)
'pacmanputsprite(3,21,70,4,3)
'pacmanputsprite(4,21,90,4,3)
'pacmanputsprite(5,21,110,4,3)
'pacmanputsprite(6,21,130,4,3)
'pacmanputsprite(7,21,150,4,3)
'
'seed=0
'
'poke $4300,code("*")
'poke $4200,code("*")
'poke $4100,code("*")
'
'poke $4010,code("0")
'poke $400F,code("1")
'poke $4030,code("2")
'poke $402F,code("3")
'
'poke $43D0,code("0")
'poke $43CF,code("1")
'poke $43F0,code("2")
'poke $43EF,code("3")
'
'for ee2=0 to 11
'  poke ($4000+((ee2+12)*32)+13) bxor %0000001111100000,peek(@text01+ee2)
'  next
'
'for ee2=0 to 11
'  poke ($4000+(0*32)+(ee2+12)) bxor %0000000000011111,peek(@text01+ee2)+64
'  next
'
'for ee2=0 to 11
'  poke ($4000+(31*32)+(ee2+12)) bxor %0000000000011111,peek(@text01+ee2)+128
'  next
'
'ee4=0
'for ee3=15 to 15+15
'  for ee2=12 to 12+15
'    poke ($4000+(ee2*32)+ee3) bxor %0000001111100000,ee4
'    ee4=ee4+1
'    next
'    next
'
'for ee2=22 to 25
'  for ee3=6 to 9
'    poke ($4000+(ee2*32)+ee3) bxor %0000001111100000,code("X")
'    next
'    next
'
'test1(377,2445,63888,2342)
'
'eee=$4207
'i=code("Q")
'poke eee,i
'eee=eee+1
'i=code("T")
'poke eee,i
'
'seed=0
'for eee=$4400 to $47FF
'  seed=smsrnd(seed)
'  poke eee,seed
'  next
'
'ex0=20:ey0=10
'ex1=20:ey1=30
'ex2=20:ey2=50
'ex3=20:ey3=70
'ex4=20:ey4=90
'ex5=20:ey5=110
'ex6=20:ey6=130
'ex7=20:ey7=150
'eee=0
'ecsp=0:ecsq=0
'
'do
'poke $50C0,255 '- watchdog? - it seems to work! thanks, Jim Bagley!!!!
'
'ej0=peek($5000) bxor $ff
'ej1=peek($5040) bxor $ff
'
'poke ($4000+(6*32)+20) bxor %0000001111100000,ej0
'poke ($4000+(7*32)+20) bxor %0000001111100000,ej1
'
'poke ($4000+(8*32)+22) bxor %0000001111100000,48+(ex0 mod 10)
'poke ($4000+(7*32)+22) bxor %0000001111100000,48+((int(ex0/10)) mod 10)
'poke ($4000+(6*32)+22) bxor %0000001111100000,48+((int(ex0/100)) mod 10)
'
'poke ($4000+(8*32)+23) bxor %0000001111100000,48+(ey0 mod 10)
'poke ($4000+(7*32)+23) bxor %0000001111100000,48+((int(ey0/10)) mod 10)
'poke ($4000+(6*32)+23) bxor %0000001111100000,48+((int(ey0/100)) mod 10)
'
'poke ($4000+(8*32)+24) bxor %0000001111100000,48+(eee mod 10)
'poke ($4000+(7*32)+24) bxor %0000001111100000,48+((int(eee/10)) mod 10)
'poke ($4000+(6*32)+24) bxor %0000001111100000,48+((int(eee/100)) mod 10)
'poke ($4000+(5*32)+24) bxor %0000001111100000,48+((int(eee/1000)) mod 10)
'poke ($4000+(4*32)+24) bxor %0000001111100000,48+((int(eee/10000)) mod 10)
'
'
'poke ($4000+(8*32)+26) bxor %0000001111100000,48+(ej1 mod 10)
'poke ($4000+(7*32)+26) bxor %0000001111100000,48+((int(ej1/10)) mod 10)
'poke ($4000+(6*32)+26) bxor %0000001111100000,48+((int(ej1/100)) mod 10)
'
'poke ($4000+(8*32)+27) bxor %0000001111100000,48+(ecsp mod 10)
'
'
'if ecsp=0 then:
'  if (ej0 band 1)<>0 then: ey0=ey0-1:end if
'  if (ej0 band 2)<>0 then: ex0=ex0-1:end if
'  if (ej0 band 4)<>0 then: ex0=ex0+1:end if
'  if (ej0 band 8)<>0 then: ey0=ey0+1:end if
'  end if
'
'if ecsp=1 then:
'  if (ej0 band 1)<>0 then: ey1=ey1-1:end if
'  if (ej0 band 2)<>0 then: ex1=ex1-1:end if
'  if (ej0 band 4)<>0 then: ex1=ex1+1:end if
'  if (ej0 band 8)<>0 then: ey1=ey1+1:end if
'  end if
'
'if ecsp=2 then:
'  if (ej0 band 1)<>0 then: ey2=ey2-1:end if
'  if (ej0 band 2)<>0 then: ex2=ex2-1:end if
'  if (ej0 band 4)<>0 then: ex2=ex2+1:end if
'  if (ej0 band 8)<>0 then: ey2=ey2+1:end if
'  end if
'
'if ecsp=3 then:
'  if (ej0 band 1)<>0 then: ey3=ey3-1:end if
'  if (ej0 band 2)<>0 then: ex3=ex3-1:end if
'  if (ej0 band 4)<>0 then: ex3=ex3+1:end if
'  if (ej0 band 8)<>0 then: ey3=ey3+1:end if
'  end if
'
'if ecsp=4 then:
'  if (ej0 band 1)<>0 then: ey4=ey4-1:end if
'  if (ej0 band 2)<>0 then: ex4=ex4-1:end if
'  if (ej0 band 4)<>0 then: ex4=ex4+1:end if
'  if (ej0 band 8)<>0 then: ey4=ey4+1:end if
'  end if
'
'if ecsp=5 then:
'  if (ej0 band 1)<>0 then: ey5=ey5-1:end if
'  if (ej0 band 2)<>0 then: ex5=ex5-1:end if
'  if (ej0 band 4)<>0 then: ex5=ex5+1:end if
'  if (ej0 band 8)<>0 then: ey5=ey5+1:end if
'  end if
'
'if ecsp=6 then:
'  if (ej0 band 1)<>0 then: ey6=ey6-1:end if
'  if (ej0 band 2)<>0 then: ex6=ex6-1:end if
'  if (ej0 band 4)<>0 then: ex6=ex6+1:end if
'  if (ej0 band 8)<>0 then: ey6=ey6+1:end if
'  end if
'
'if ecsp=7 then:
'  if (ej0 band 1)<>0 then: ey7=ey7-1:end if
'  if (ej0 band 2)<>0 then: ex7=ex7-1:end if
'  if (ej0 band 4)<>0 then: ex7=ex7+1:end if
'  if (ej0 band 8)<>0 then: ey7=ey7+1:end if
'  end if
'
'if (ej1 band 15)<>0 then: ecsq=ecsq+1:end if
'ecsp=(int(ecsq/4))mod 8
'
'ee3=int(eee/4)
'
'pacmanputsprite(0,ex0,ey0,4,3)  '- layer,x,y,id,clut
'pacmanputsprite(1,ex1,ey1,ee3,3)  '- layer,x,y,id,clut
'pacmanputsprite(2,ex2,ey2,4,ee3)  '- layer,x,y,id,clut
'pacmanputsprite(3,ex3,ey3,ee3,ee3)  '- layer,x,y,id,clut
'pacmanputsprite(4,ex4,ey4,4,3)  '- layer,x,y,id,clut
'pacmanputsprite(5,ex5,ey5,ee3,3)  '- layer,x,y,id,clut
'pacmanputsprite(6,ex6,ey6,4,ee3)  '- layer,x,y,id,clut
'pacmanputsprite(7,ex7,ey7,ee3,ee3)  '- layer,x,y,id,clut
'
'eee=eee+1
'loop
'
''-------------------------------------------------------------------------------
'
'do
'loop
'
''-------------------------------------------------------------------------------
'
'text01:
'asm
'  defb "HELLO WORLD!!!!!"
'  end asm
'
''-------------------------------------------------------------------------------
'
'poke $5000,255
'
''- this should put some characters on the pattern display area
'for i=0 to 255
'  poke $4040+i,i
'  poke $4440+i,i
'  next
'
'do
'loop
'
''-------------------------------------------------------------------------------
'
'
'
